#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../my_codeh/play.h"

Node* p1;
LinkedList* list;
char * result;
int music_flag = 1;

char* ctr_music_init()
{
	list = readdir_mp3(); 
	result = concatListToString(list); 
	p1=list->first;
	return result;
}
void ctr_music(LinkedList* l,int music_flag)
{
	
    switch (music_flag)
	{	
		char cmd[100] = {0};
		case STOP:	system("killall -STOP madplay");	break;	//	暂停
		case CONT:	system("killall -CONT madplay");	break;	//	继续
		case KILL:	system("killall -KILL madplay");	break;	//	结束
		case NEXT: 
				p1=p1->next;
				sprintf(cmd,"madplay -Q %s -a 3 &",p1->data);
				system("killall -KILL madplay");		//	需要先杀死当前的播放,再播放下一首
				system(cmd);
				break;
		case PREV: 
				p1=p1->prev;
				sprintf(cmd,"madplay -Q %s -a 3 &",p1->data);
				system("killall -KILL madplay");		//	需要先杀死当前的播放,再播放下一首
				system(cmd);	
				break;
		case PLAY:
				sprintf(cmd,"madplay -Q %s -a 3 &",p1->data);
				system("killall -KILL madplay");		//	需要先杀死当前的播放,再播放下一首
				system(cmd);
				break;
	}
		
}



